home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / mmdf / mmdf-IIb.43 / src / pop / po_wtmail.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-02-28  |  16.5 KB  |  776 lines

  1. #ifndef    POP
  2. /* bb_wtmail.c - write mail to a BBoard */
  3. #else /* POP */
  4. /* po_wtmail.c - write mail for a POP subscriber */
  5. #endif /* POP */
  6.  
  7.  
  8. #include "util.h"
  9. #include "mmdf.h"
  10. #include "bboards.h"
  11. #include "cnvtdate.h"
  12. #include "ch.h"
  13. #include "phs.h"
  14. #include <pwd.h>
  15. #include <sys/stat.h>
  16.  
  17. /*   */
  18.  
  19. #ifndef    RP_DOK
  20. #define    submitopts    "vmth%s*"
  21. #else /* RP_DOK */
  22. #define    submitopts    "vkmth%s*"
  23. #endif /* RP_DOK */
  24.  
  25. #ifndef    POP
  26. #define    RP_NOPE    RP_AOK
  27.  
  28. #define    MBXMODE    BBMODE
  29. #else /* POP */
  30. #define    RP_NOPE    RP_USER
  31.  
  32. #define    MBXMODE    sentprotect
  33.  
  34. extern int   sentprotect;
  35. #endif /* POP */
  36.  
  37.  
  38. int    err_fd = NOTOK;
  39.  
  40. int     ds_address ();
  41.  
  42. extern int  errno;
  43.  
  44. int    bbrduid, bbrdgid;
  45.  
  46. char   *chnlname,
  47.         chnlinfo[LINESIZE];
  48. #ifndef    POP
  49. char    bbrdaddr[LINESIZE],
  50.         bbrdfrom[LINESIZE],
  51.         bbrdheader[LINESIZE],
  52.     bbrdhome[LINESIZE],
  53.         bbrdtime[LINESIZE];
  54. #endif /* not POP */
  55.  
  56. extern char *qu_msgfile,
  57.             *delim1,
  58.             *delim2,
  59.         *lckdfldir,
  60.             *locfullmachine,
  61.             *locfullname,
  62.         *sitesignature,
  63.         *supportaddr;
  64.  
  65. struct bboard  *curbb;
  66.  
  67. extern LLog *logptr;
  68.  
  69. FILE *lk_fopen();
  70.  
  71. long    lseek ();
  72. char   *index (), *rindex ();
  73. #ifdef SYS5
  74. int sprintf ();
  75. #else
  76. char *sprintf ();
  77. #endif
  78. struct passwd  *getpwnam ();
  79.  
  80. /*   */
  81.  
  82. bb_init (chanptr)
  83. Chan * chanptr;
  84. {
  85.     int     uid,
  86.             eid;
  87.     struct passwd *pw;
  88.  
  89. #ifdef DEBUG
  90.     ll_log (logptr, LLOGBTR, "bb_init(chanptr=%s)", chanptr -> ch_name);
  91. #endif
  92.  
  93.     chnlname = chanptr -> ch_name;
  94. #ifndef    notdef
  95.     sprintf (chnlinfo, submitopts, chnlname);
  96. #else /* notdef            /* the following is probably a BAD idea */
  97.     if (chanptr -> ch_host == NULL)
  98.     chnlinfo[0] = NULL;    /* local delivery ONLY */
  99.     else
  100.     sprintf (chnlinfo, submitopts, chanptr -> ch_host);
  101. #endif /* notdef */
  102.  
  103. #ifndef    POP
  104.     if ((pw = getpwnam (BBOARDS)) == NULL)
  105.     err_abrt (RP_BHST, "no passwd entry for '%s'", BBOARDS);
  106. #else /* POP */
  107.     if ((pw = getpwnam (POPUID)) == NULL)
  108.     err_abrt (RP_BHST, "no passwd entry for '%s'", POPUID);
  109. #endif /* POP */
  110.  
  111.     bbrduid = pw -> pw_uid;
  112.     bbrdgid = pw -> pw_gid;
  113. #ifndef    POP
  114.     if (isstr (locfullmachine))
  115.     sprintf (bbrdfrom, "%s@%s", pw -> pw_name, locfullmachine);
  116.     else
  117.     sprintf (bbrdfrom, "%s@%s", pw -> pw_name, locfullname);
  118. #ifdef DEBUG
  119.     ll_log (logptr, LLOGGEN, "distributing as '%s'", bbrdfrom);
  120. #endif
  121.     sprintf (bbrdhome, pw -> pw_dir);
  122. #endif /* not POP */
  123.  
  124. #ifndef    POP
  125.     if (!setbbent ())
  126.     err_abrt (RP_BHST, "setbbent() failed");
  127. #else /* POP */
  128.     if (!setpwinfo (pw, POPDB, 1))
  129.     err_abrt (RP_BHST, "setbbinfo(%s, %s, 1) failed",
  130.         pw -> pw_name, POPDB);
  131. #endif /* POP */
  132.  
  133.     getwho (&uid, &eid);
  134.     if (eid != 0)
  135.     err_abrt (RP_BHST, "not running as root");
  136.  
  137.     return RP_OK;
  138. }
  139.  
  140.  
  141. bb_end (result)
  142. short   result;
  143. {
  144. #ifdef DEBUG
  145.     ll_log (logptr, LLOGBTR, "bb_end(result=0%o)", result);
  146. #endif
  147.  
  148.     return RP_OK;
  149. }
  150.  
  151. /*   */
  152.  
  153. bb_sbinit () {
  154. #ifdef DEBUG
  155.     ll_log (logptr, LLOGBTR, "bb_sbinit()");
  156. #endif
  157.  
  158.     return RP_OK;
  159. }
  160.  
  161.  
  162. bb_sbend () {
  163. #ifdef DEBUG
  164.     ll_log (logptr, LLOGBTR, "bb_sbend()");
  165. #endif
  166.  
  167.     return RP_OK;
  168. }
  169.  
  170. /*   */
  171.  
  172. bb_winit (info, sender)
  173. char   *info,
  174.        *sender;
  175. {
  176. #ifdef DEBUG
  177.     ll_log (logptr, LLOGBTR, "bb_winit(info='%s',sender='%s')",
  178.         info, sender);
  179. #endif
  180.  
  181.     return RP_OK;
  182. }
  183.  
  184. /*   */
  185.  
  186. bb_wtadr (host, adr)
  187. char   *host,
  188.        *adr;
  189. {
  190.     short   count,
  191.             result;
  192.     int     len,
  193.         md,
  194.             offset,
  195.         size;
  196.     long    start,
  197.             stop,
  198.             pos;
  199.     char   *cp,
  200.             buffer[BUFSIZ];
  201.  
  202. #ifdef DEBUG
  203.     ll_log (logptr, LLOGBTR, "bb_wtadr(host=%s,adr=%s)", host, adr);
  204. #endif
  205.  
  206.     if ((cp = index (adr, '@')) != NULL)
  207.     *cp = NULL;
  208.     make_lower (adr, adr);
  209.     if ((curbb = getbbnam (adr)) == NULL)
  210.     return RP_USER;
  211. #ifndef    POP
  212.     if (isstr (locfullmachine))
  213.     sprintf(bbrdaddr,"local-%s-request@%s", curbb->bb_name, locfullmachine);
  214.     else
  215.     sprintf(bbrdaddr,"local-%s-request@%s", curbb->bb_name, locfullname);
  216. #endif /* not POP */
  217. #ifdef DEBUG
  218.     ll_log (logptr, LLOGGEN, "=> BBoard %s: file='%s' info='%s'",
  219.         curbb -> bb_name, curbb -> bb_file, curbb -> bb_info);
  220. #endif
  221.  
  222.     if (curbb -> bb_file == NULL || *curbb -> bb_file == NULL)
  223.     return RP_NOPE;
  224. #ifdef DEBUG
  225.     ll_log (logptr, LLOGGEN, "begin local delivery...");
  226. #endif
  227.     printx ("\r\nperforming local delivery to file %s...\n",
  228.         curbb -> bb_file);
  229.  
  230.     qu_rtinit (0L);
  231.  
  232.     if ((md = mbx_open (curbb -> bb_file, bbrduid, bbrdgid, MBXMODE)) == NOTOK)
  233.     return RP_FIO;
  234.  
  235. #ifndef    POP
  236.     if (rp_isbad (result = mbx_init ())) {
  237.     mbx_close (curbb -> bb_file, md);
  238.     return result;
  239.     }
  240. #endif /* not POP */
  241.  
  242.     pos = lseek (md, 0L, 1);
  243.     count = strlen (delim1);
  244.     if (write (md, delim1, count) != count) {
  245.     ll_log (logptr, LLOGTMP, "error writing delim1");
  246.     result = NOTOK;
  247.     goto clean_up;
  248.     }
  249.     start = lseek (md, 0L, 1);
  250.     size = 0;
  251.  
  252. #ifndef    POP
  253.     count = strlen (bbrdheader);
  254.     if (write (md, bbrdheader, count) != count) {
  255.     ll_log (logptr, LLOGTMP, "error writing BBoard information");
  256.     result = NOTOK;
  257.     goto clean_up;
  258.     }
  259.     for (cp = bbrdheader; *cp; cp++, size++)
  260.     if (*cp == '\n')
  261.         size++;
  262. #endif /* not POP */
  263.  
  264.     for (len = BUFSIZ;
  265.         rp_gval (result = qu_rtxt (buffer, &len)) == RP_OK;
  266.         len = BUFSIZ) {
  267.     for (offset = 0;
  268.         (offset = strindex (delim1, buffer)) >= 0;
  269.         buffer[offset]++)
  270.         continue;
  271.     for (offset = 0;
  272.         (offset = strindex (delim2, buffer)) >= 0;
  273.         buffer[offset]++)
  274.         continue;
  275.     if (write (md, buffer, len) != len) {
  276.         ll_log (logptr, LLOGTMP, "error writing to file '%s'",
  277.             curbb -> bb_file);
  278.         result = NOTOK;
  279.         goto clean_up;
  280.     }
  281.     for (offset = 0, cp = buffer; offset < len; offset++, size++)
  282.         if (*cp++ == '\n')
  283.         size++;
  284.     }
  285.  
  286.     if (result < 0)
  287.     ll_log (logptr, LLOGTMP, "error reading from message file '%s'",
  288.         qu_msgfile);
  289. clean_up: ;
  290.  
  291.     stop = lseek (md, 0L, 1);
  292.     count = strlen (delim2);
  293.     if (write (md, delim2, count) != count)
  294.     ll_log (logptr, LLOGTMP, "error writing delim2");
  295.     map_write (curbb -> bb_file, md, curbb -> bb_maxima, start, stop, pos,
  296.     size, 0);
  297. #ifdef DEBUG
  298.     ll_log (logptr, LLOGGEN, "end local delivery...");
  299. #endif
  300.  
  301.     if (result < 0)
  302.     mbx_close (curbb -> bb_file, md);
  303.     else
  304.     result = mbx_close (curbb -> bb_file, md);
  305.  
  306.     return (result != NOTOK ? RP_OK : RP_FIO);
  307. }
  308.  
  309. /*   */
  310.  
  311. bb_txtcpy () {
  312. #ifndef    POP
  313.     short   result;
  314.  
  315. #ifdef    DEBUG
  316.     ll_log (logptr, LLOGBTR, "bb_txtcpy()");
  317. #endif
  318.  
  319.     if (curbb -> bb_dist == NULL
  320.         || *curbb -> bb_dist == NULL
  321.         || chnlinfo[0] == NULL)
  322.     return RP_MOK;
  323. #ifdef DEBUG
  324.     ll_log (logptr, LLOGGEN, "begin distribution...");
  325. #endif
  326.     if (curbb -> bb_file == NULL || *curbb -> bb_file == NULL)
  327.     printx ("\r\n");
  328.     printx("\rperforming remote distribution\n");
  329.  
  330.     if (rp_isbad (result = dist_init ())
  331.         || rp_isbad (result = dist_adrs ())
  332.         || rp_isbad (result = dist_text ())
  333.         || rp_isbad (result = dist_end ()))
  334.     return dist_lose (result);
  335. #ifdef DEBUG
  336.     ll_log (logptr, LLOGGEN, "end distribution...");
  337. #endif
  338.  
  339.     if (err_fd != NOTOK)
  340.     dist_lose (RP_MOK);
  341.     else
  342.     printx ("\rmessage distributed\n");
  343. #endif /* not POP */
  344.  
  345.     return RP_MOK;
  346. }
  347.  
  348. /*   */
  349.  
  350. #ifndef    POP
  351. /* **************** (dist_)  BBOARD DISTRIBUTION **************** */
  352.  
  353. dist_init () {
  354.     short   result;
  355. #ifdef    RP_NS
  356.     int        len;
  357.     struct rp_bufstruct reply;
  358. #endif /* RP_NS */
  359.  
  360. #ifdef DEBUG
  361.     ll_log (logptr, LLOGBTR, "dist_init()");
  362. #endif
  363.  
  364.     if (rp_isbad (result = mm_init ()))
  365.     return ds_log (result, LLOGFAT, "mm_init() failed [%s]",
  366.         rp_valstr (result));
  367.     if (rp_isbad (result = mm_sbinit ()))
  368.     return ds_log (result, LLOGFAT, "mm_sbinit() failed [%s]",
  369.         rp_valstr (result));
  370.     if (rp_isbad (result = mm_winit (chnlname, chnlinfo, bbrdaddr)))
  371.     return ds_log (result, LLOGFAT,
  372.         "mm_winit('%s','%s','%s') failed [%s]",
  373.         chnlname, chnlinfo, bbrdaddr, rp_valstr (result));
  374. #ifdef    RP_NS
  375.     if (rp_isbad (result = mm_rrply (&reply, &len)))
  376.         return ds_log (result, LLOGFAT, "problem with sender address [%s]",
  377.             rp_valstr (result));
  378. #endif /* RP_NS */
  379.  
  380.     return result;
  381. }
  382.  
  383. /*   */
  384.  
  385. dist_adrs ()
  386. {
  387.     short   result;
  388.  
  389. #ifdef DEBUG
  390.     ll_log (logptr, LLOGBTR, "dist_adrs()");
  391. #endif
  392.  
  393.     if (getbbdist (curbb, ds_address))
  394.     return ds_log (RP_NO, LLOGTMP, "getbbdist failed: %s", getbberr ());
  395.  
  396.     if (rp_isbad (result = mm_waend ()))
  397.     return ds_log (result, LLOGFAT, "mm_waend() failed [%s]",
  398.         rp_valstr (result));
  399.  
  400.     return result;
  401. }
  402.  
  403. /*   */
  404.  
  405. ds_address (addr, host)
  406. char *addr,            /* local part */
  407.      *host;            /* rest */
  408. {
  409.     short   result;
  410.     int     len;
  411.     struct rp_bufstruct reply;
  412.  
  413. #ifdef DEBUG
  414.     ll_log (logptr, LLOGBTR, "ds_address(addr='%s',host='%s')", addr, host);
  415. #endif
  416.  
  417.     printx ("\rperforming distribution to %s@%s...\n", addr, host);
  418.     if (rp_isbad (result = mm_wadr (host, addr))) {
  419.     ds_log (result, LLOGFAT, "mm_wadr('%s','%s') failed [%s]",
  420.         host, addr, rp_valstr (result));
  421.     return NOTOK;
  422.     }
  423.     if (rp_isbad (result = mm_rrply (&reply, &len))) {
  424.     ds_log (result, LLOGFAT,
  425.         "mm_rrply() failed [%s] getting status of '%s@%s'",
  426.         rp_valstr (result), addr, host);
  427.     return NOTOK;
  428.     }
  429.  
  430.     switch (rp_gval (reply.rp_val)) {
  431.     case RP_AOK:
  432. #ifdef    RP_DOK
  433.     case RP_DOK:
  434. #endif /* RP_DOK */
  435. #ifdef DEBUG
  436.         ll_log (logptr, LLOGGEN, "address '%s@%s' [%s] -- %s",
  437.             addr, host, rp_valstr (reply.rp_val), reply.rp_line);
  438. #endif
  439.         return OK;
  440.  
  441.     case RP_NO:
  442. #ifdef    RP_NS
  443.     case RP_NS:
  444. #endif /* RP_NS */
  445.     case RP_USER:
  446.     case RP_NDEL:
  447.     case RP_AGN:
  448.     case RP_NOOP:
  449.         ds_log (reply.rp_val, LLOGTMP, "address '%s@%s' [%s] -- %s",
  450.             addr, host, rp_valstr (reply.rp_val), reply.rp_line);
  451.         return OK;        /* fail-soft */
  452.  
  453.     default:
  454.         ds_log (reply.rp_val, LLOGFAT, "unexpected reply [%s] -- %s",
  455.             rp_valstr (reply.rp_val), reply.rp_line);
  456.         return NOTOK;
  457.     }
  458. }
  459.  
  460. /*   */
  461.  
  462. dist_text ()
  463. {
  464.     short   result;
  465.     int     len;
  466.     char    buffer[BUFSIZ];
  467.  
  468. #ifdef DEBUG
  469.     ll_log (logptr, LLOGBTR, "dist_text()");
  470. #endif
  471.  
  472.     qu_rtinit (0L);
  473.     for (len = BUFSIZ;
  474.         rp_gval (result = qu_rtxt (buffer, &len)) == RP_OK;
  475.         len = BUFSIZ)
  476.     if (rp_isbad (result = mm_wtxt (buffer, len)))
  477.         return ds_log (result, LLOGFAT, "mm_wtxt() failed [%s]",
  478.             rp_valstr (result));
  479.  
  480.     if (result < 0)
  481.     return ds_log (RP_FIO, LLOGTMP,
  482.         "error reading from message file '%s'", qu_msgfile);
  483.  
  484.     if (rp_isbad (result = mm_wtend ()))
  485.     return ds_log (result, LLOGFAT, "mm_wtend() failed [%s]",
  486.         rp_valstr (result));
  487.  
  488.     return result;
  489. }
  490.  
  491. /*   */
  492.  
  493. dist_end ()
  494. {
  495.     short   result;
  496.     int     len;
  497.     struct rp_bufstruct reply;
  498.  
  499. #ifdef DEBUG
  500.     ll_log (logptr, LLOGBTR, "dist_end()");
  501. #endif
  502.  
  503.     if (rp_isbad (result = mm_rrply (&reply, &len)))
  504.     return ds_log (result, LLOGFAT,
  505.         "mm_rrply() failed [%s] getting final status",
  506.         rp_valstr (result));
  507.  
  508.     switch (rp_gval (reply.rp_val)) {
  509.     case RP_OK:
  510.     case RP_MOK:
  511. #ifdef DEBUG
  512.         ll_log (logptr, LLOGGEN, "message [%s] -- %s",
  513.             rp_valstr (reply.rp_val), reply.rp_line);
  514. #endif
  515.         mm_sbend ();
  516.         mm_end (OK);
  517.         return result;
  518.  
  519.     case RP_NO:
  520.     case RP_NDEL:
  521.     case RP_AGN:
  522.     case RP_NOOP:
  523.         return ds_log (RP_NO, LLOGTMP, "not delivered [%s] -- %s",
  524.             rp_valstr (reply.rp_val), reply.rp_line);
  525.  
  526.     default:
  527.         return ds_log (RP_RPLY, LLOGFAT,
  528.             "unexpected final reply [%s] -- %s",
  529.             rp_valstr (reply.rp_val), reply.rp_line);
  530.     }
  531. }
  532.  
  533. /*   */
  534.  
  535. dist_lose (result)
  536. short   result;
  537. {
  538.     int     i;
  539.     char   *cp,
  540.             intro[BUFSIZ],
  541.             buffer[BUFSIZ];
  542.  
  543. #ifdef    DEBUG
  544.     ll_log (logptr, LLOGBTR, "dist_lose(result=0%o)", result);
  545. #endif /* DEBUG */
  546.  
  547.     mm_end (NOTOK);
  548.  
  549.     printx ("\rerrors during distribution: ");
  550.     if (domsg)
  551.     (void) fflush (stdout);
  552.     (void) sprintf (intro, "bboards%d distribution for %s failed [%s]\n",
  553.         getpid (), curbb -> bb_name, rp_valstr (result));
  554.     if (loseaux (bbrdaddr, bbrdfrom, intro) != OK
  555.         && loseaux (bbrdfrom, (char *) 0, intro) != OK) {
  556.     printx ("unable to post advisory.\n");
  557.     ll_log (logptr, LLOGFAT, "unable to post failure notice");
  558.     if (err_fd != NOTOK) {
  559.         (void) lseek (err_fd, 0L, 0);
  560.         if ((i = read (err_fd, buffer, sizeof buffer)) > 0) {
  561.         buffer[i] = NULL;
  562.         if (cp = index (buffer, '\n'))
  563.             *cp = NULL;
  564.         ll_log (logptr, LLOGFAT, "info: %s", buffer);
  565.         }
  566.     }
  567.     if (loseaux (supportaddr, (char *) 0, intro) != NOTOK)
  568.         ll_log (logptr, LLOGFAT, "unable to advise %s of failure!",
  569.             supportaddr);
  570.     }
  571.     else
  572.     printx ("advisory posted.\n");
  573.     if (domsg)
  574.     (void) fflush (stdout);
  575.  
  576.     if (err_fd != NOTOK) {
  577.     close (err_fd);
  578.     err_fd = NOTOK;
  579.     }
  580.     return RP_MOK;
  581. }
  582.  
  583. /*   */
  584.  
  585. int    loseaux (to, cc, intro)
  586. char   *to,
  587.        *cc,
  588.        *intro;
  589. {
  590.     int     i;
  591.     char    buffer[BUFSIZ];
  592.  
  593.     if (ml_init (NO, NO, sitesignature, "Re-distribution Failure") != OK
  594.         || ml_adr (to) != OK)
  595.     return NOTOK;
  596.     if (cc && (ml_cc () != OK || ml_adr (cc) != OK))
  597.     return NOTOK;
  598.     if (ml_aend () != OK || ml_tinit () != OK)
  599.     return NOTOK;
  600.  
  601.     ml_txt (intro);
  602.     if (err_fd != NOTOK) {
  603.     lseek (err_fd, 0L, 0);
  604.     while ((i = read (err_fd, buffer, sizeof buffer)) > 0) {
  605.         buffer[i] = NULL;
  606.         ml_txt (buffer);
  607.     }
  608.     }
  609.     encap ();
  610.  
  611.     return ml_end (OK);
  612. }
  613.  
  614. /*   */
  615.  
  616. /* very similar to sbr/cpydgst.c */
  617.  
  618. #define    S1    0
  619. #define    S2    1
  620.  
  621. #define    output(c)    if (bp >= dp) {flush (); *bp++ = c;} else *bp++ = c
  622. #define    flush()        if (bp - outbuf) \
  623.                 *bp = NULL, ml_txt (outbuf), bp = outbuf
  624.  
  625. static  encap () {
  626.     register int    state;
  627.     short   result;
  628.     int     len,
  629.         init;
  630.     register char  *cp,
  631.                    *ep;
  632.     char    buffer[BUFSIZ];
  633.     register char  *bp,
  634.                    *dp;
  635.     char    outbuf[BUFSIZ];
  636.  
  637.     qu_rtinit (0L);
  638.  
  639.     dp = (bp = outbuf) + sizeof outbuf;
  640.     init = 0;
  641.     for (state = S1, len = BUFSIZ;
  642.         rp_gval (result = qu_rtxt (buffer, &len)) == RP_OK;
  643.         len = BUFSIZ)
  644.     for (ep = (cp = buffer) + len; cp < ep; cp++) {
  645.         if (*cp == NULL)
  646.         continue;
  647.         switch (state) {
  648.         case S1: 
  649.             if (*cp == '-') {
  650.             if (init == 0) {
  651.                 ml_txt ("\n------- Forwarded Message\n\n");
  652.                 init++;
  653.             }
  654.             output ('-');
  655.             output (' ');
  656.             }
  657.             state = S2;    /* fall */
  658.  
  659.         case S2: 
  660.             if (init == 0) {
  661.             ml_txt ("\n------- Forwarded Message\n\n");
  662.             init++;
  663.             }
  664.             output (*cp);
  665.             if (*cp == '\n')
  666.             state = S1;
  667.             break;
  668.         }
  669.     }
  670.  
  671.     flush ();
  672.  
  673.     if (result < 0) {
  674.     ll_log (logptr, LLOGTMP, "error reading message when noting failure");
  675.     if (init)
  676.         ml_txt ("\n------- End of Forwarded Message\n\n");
  677.     ml_txt ("[ error reading message ]\n");
  678.     }
  679.     else
  680.     if (init)
  681.         ml_txt ("\n------- End of Forwarded Message\n\n");
  682.     else {
  683.         ll_log (logptr, LLOGTMP, "message empty when noting failure");
  684.         ml_txt ("[ message empty ]\n");
  685.     }
  686. }
  687.  
  688. /*   */
  689.  
  690. /* VARARGS3 */
  691.  
  692. ds_log (result, level, fmt, a, b, c, d, e)
  693. short   result;
  694. int     level;
  695. char   *fmt,
  696.        *a,
  697.        *b,
  698.        *c,
  699.        *d,
  700.        *e;
  701. {
  702.     int     i;
  703.     char    buffer[BUFSIZ],
  704.         tmpfil[BUFSIZ];
  705.  
  706.     ll_log (logptr, level, fmt, a, b, c, d, e);
  707.  
  708.     sprintf (buffer, fmt, a, b, c, d, e);
  709.     strcat (buffer, "\n");
  710.  
  711.     printx ("\rerror: %s", buffer);
  712.  
  713.     if (err_fd == NOTOK) {
  714.     unlink (mktemp (strcpy (tmpfil, "/tmp/bboardsXXXXXX")));
  715.     if ((err_fd = creat (tmpfil, 0600)) == NOTOK)
  716.         return result;
  717.     close (err_fd);
  718.     if ((err_fd = open (tmpfil, 2)) == NOTOK)
  719.         return result;
  720.     unlink (tmpfil);
  721.     lseek (err_fd, 0L, 0);
  722.     }
  723.     i = strlen (buffer);
  724.     write (err_fd, buffer, i);
  725.  
  726.     return result;
  727. }
  728. #endif /* not POP */
  729.  
  730. /*   */
  731.  
  732. /* mbx_        local mailbox routines */
  733.  
  734. #ifndef    POP
  735. mbx_init () {
  736.     int     fd,
  737.             clear;
  738.     char    name[BUFSIZ];
  739.     FILE * fp;
  740.  
  741.     if ((fd = mbx_Xopen (curbb -> bb_info, bbrduid, bbrdgid, MBXMODE, &clear))
  742.         == NOTOK) {
  743.     if (errno == ETXTBSY) {
  744.         printx ("\runable to lock %s\n", curbb -> bb_info);
  745.         ll_err (logptr, LLOGTMP, "unable to lock %s",
  746.             curbb -> bb_info);
  747.         return RP_LOCK;
  748.     }
  749.     printx ("\runable to open '%s'", curbb -> bb_info);
  750.     ll_log (logptr, LLOGTMP, "unable to open '%s'", curbb -> bb_info);
  751.     return RP_FOPN;
  752.     }
  753.     if ((fp = fdopen (fd, "w")) == (FILE *) NULL) {
  754.     printx ("\runable to fdopen '%s'", curbb -> bb_info);
  755.     ll_err (logptr, LLOGTMP, "unable to fdopen '%s'", curbb -> bb_info);
  756.     mbx_close (curbb -> bb_info, fd);
  757.     return RP_LIO;
  758.     }
  759.  
  760.     strcpy (name, curbb -> bb_name);
  761.     if ((curbb = getbbnam (name)) == (struct bboard *) NULL) {
  762.     printx ("\runable to get information on BBoard %s\n", name);
  763.     ll_err (logptr, LLOGFAT, "unable to get info on %s", name);
  764.     lkfclose (fp, curbb -> bb_info);
  765.     return RP_LIO;
  766.     }
  767.     sprintf (bbrdheader, "BBoard-ID: %d\nBB-Posted: %s\n",
  768.         ++curbb -> bb_maxima, cnvtdate (TIMREG, bbrdtime));
  769.     fprintf (fp, "%d\n%s\n", curbb -> bb_maxima, bbrdtime);
  770.  
  771.     lkfclose (fp, curbb -> bb_info);
  772.  
  773.     return RP_OK;
  774. }
  775. #endif /* not POP */
  776.